using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using DevExpress.XtraReports.UI;
using NetROS.Tiers.Entities;
using System.Windows.Forms;

namespace NetRosApp.Klijenti.Reports
{
    public partial class OtpremnicaIspis : DevExpress.XtraReports.UI.XtraReport, IParametriIzvjestaja
    {
        public OtpremnicaIspis()
        {
            InitializeComponent();
        }

        public OtpremnicaIspis(Dokument dokument)
        {
            InitializeComponent();
            bindingSource1.DataSource = dokument;
        //    if (dokument.IDDokumentTip == 30) xrLabel55.Visible = false;
           // xrDatumMjesto.Text = string.Format("[IDOrganizacijaOdSource.IDMjestoSource.Naziv], {0}", DateTime.Now.ToShortDateString());
            xrDatumMjesto.Text = "[IDOrganizacijaOdSource.IDMjestoSource.Naziv], [Datum!dd.MM.yyyy]";
            //System.Drawing.Imaging.Metafile tmp = new System.Drawing.Imaging.Metafile(@"H:\NetROS\NetRosApp\Slike\Reporti\zaglavlje.wmf");
            //System.Drawing.Imaging.Metafile tmp = new System.Drawing.Imaging.Metafile(Application.StartupPath + "\\zaglavlje.wmf");
            //int visina = tmp.Size.Height;
            //int duzina = tmp.Size.Width;
            //if (visina != 0)
            //{
            //    xrPictureBox1.Height = (int)(((decimal)tmp.Height / (decimal)tmp.Width) * (decimal)625);
            //}

            //xrPictureBox1.Image = tmp;


        }

        #region IParametriIzvjestaja Members

        public void SetParametri()
        {
            xrLParametar1.Text = (bindingSource1.DataSource as Dokument).IDDokumentTipSource.PrilagodenDokumentTip.Parametar1;
             XrLabelParametar2.Text = (bindingSource1.DataSource as Dokument).IDDokumentTipSource.PrilagodenDokumentTip.Parametar2;
            String Otpremnice = String.Empty;
            foreach (Veza tmp in (bindingSource1.DataSource as Dokument).VezaCollectionGetByIDParent)
            {
                if (tmp.IDChildSource.IDDokumentTip == (int)DokumentTipList.Otpremnica)
                {
     //               xrLabel55.Visible = false;
                    xrLabel24.Visible = false;
                    xrLabel27.Visible = false;
                    xrlIzdatnice.Visible = true;
                    xrLOtprem.Visible = true;
                    Otpremnice += tmp.IDChildSource.Oznaka + " ";
                }
            }
            xrlIzdatnice.Text = Otpremnice;
            Dokument dokument = (bindingSource1.DataSource as Dokument);
            if (dokument != null && dokument.IDOrganizacijaOdSource != null && !String.IsNullOrEmpty(dokument.IDOrganizacijaOdSource.Adresa)
              && !String.IsNullOrEmpty(dokument.IDOrganizacijaOdSource.Telefon)
              && dokument.IDOrganizacijaOdSource.IDMjestoSource != null)
            {
                xrPanel1.Visible = true;
            }
            else
            {
                xrPanel1.Visible = false;
            }
        }

        #endregion

        private void xrLabel16_SummaryCalculated(object sender, TextFormatEventArgs e)
        {
            if (e.Value != null)
            {
     //           xrLabel16.Summary.FormatString = "{0:n2}";
            }

        }

        private void xrLabel33_BeforePrint(object sender, System.Drawing.Printing.PrintEventArgs e)
        {
            try
            {

  //              xrLabel33.Text = (bindingSource1.DataSource as Dokument).Oznaka.ToString() + "-" + (bindingSource1.DataSource as Dokument).IDKlijentSource.MB.ToString();
            }
            catch
            {
            }
        }



    }
}
